EN FR
EN FR


Section: Scientific Foundations

Automatic Differentiation

Participants : Laurent Hascoët, Valérie Pascual.


Glossary
automatic differentiation

(AD) Automatic transformation of a program, that returns a new program that computes some derivatives of the given initial program, i.e. some combination of the partial derivatives of the program's outputs with respect to its inputs.

adjoint

Mathematical manipulation of the Partial Derivative Equations that define a problem, obtaining new differential equations that define the gradient of the original problem's solution.

checkpointing

General trade-off technique, used in adjoint-mode AD, that trades duplicate execution of a part of the program to save some memory space that was used to save intermediate results. Checkpointing a code fragment amounts to running this fragment without any storage of intermediate values, thus saving memory space. Later, when such an intermediate value is required, the fragment is run a second time to obtain the required values.


Automatic or Algorithmic Differentiation (AD) differentiates programs. An AD tool takes as input a source program P that, given a vector argument XIR n , computes some vector result Y=F(X)IR m . The AD tool generates a new source program P ' that, given the argument X, computes some derivatives of F. The resulting P ' reuses the control of P.

For any given control, P is equivalent to a sequence of instructions, which is identified with a composition of vector functions. Thus, if

Pis{I 1 ;I 2 ;I p ;},F=f p f p-1 f 1 ,(1)

where each f k is the elementary function implemented by instruction I k . AD applies the chain rule to obtain derivatives of F. Calling X k the values of all variables after instruction I k , i.e. X 0 =X and X k =f k (X k-1 ), the chain rule gives the Jacobian of F

F ' (X)=f p ' (X p-1 ).f p-1 ' (X p-2 )..f 1 ' (X 0 )(2)

which can be mechanically written as a sequence of instructions I k ' . Combining the I k ' with the control of P yields P ' . This can be generalized to higher level derivatives, Taylor series, etc.

In practice, the Jacobian F ' (X) is often too expensive to compute and store, but most applications only need projections of F ' (X) such as:

  • Sensitivities, defined for a given direction X ˙ in the input space as:

    F ' (X).X ˙=f p ' (X p-1 ).f p-1 ' (X p-2 )..f 1 ' (X 0 ).X ˙.(3)

    Sensitivities are easily computed from right to left, interleaved with the original program instructions. This is the tangent mode of AD.

  • Adjoints, defined for a given weighting Y ¯ of the outputs as:

    F '* (X).Y ¯=f 1 '* (X 0 ).f 2 '* (X 1 )..f p-1 '* (X p-2 ).f p '* (X p-1 ).Y ¯.(4)

    Adjoints are most efficiently computed from right to left, because matrix×vector products are cheaper than matrix×matrix products. This is the adjoint mode of AD, most effective for optimization, data assimilation  [33] , adjoint problems [28] , or inverse problems.

Adjoint-mode AD turns out to make a very efficient program, at least theoretically [30] . The computation time required for the gradient is only a small multiple of the run-time of P. It is independent from the number of parameters n. In contrast, computing the same gradient with the tangent mode would require running the tangent differentiated program n times.

However, the X k are required in the inverse of their computation order. If the original program overwrites a part of X k , the differentiated program must restore X k before it is used by f k+1 '* (X k ). Therefore, the central research problem of adjoint-mode AD is to make the X k available in reverse order at the cheapest cost, using strategies that combine storage, repeated forward computation from available previous values, or even inverted computation from available later values.

Another research issue is to make the AD model cope with the constant evolution of modern language constructs. From the old days of Fortran77, novelties include pointers and dynamic allocation, modularity, structured data types, objects, vectorial notation and parallel communication. We regularly extend our models and tools to handle these new constructs.